import * as types from "../type";
const state = {
  userInfo: JSON.parse(sessionStorage.getItem("userInfo")) || null
};

const getters = {
  userInfo: state => {
    return state.userInfo;
  }
};

const mutations = {
  [types.SET_USER_INFO](state, data) {
    state.userInfo = data;
    sessionStorage.setItem("userInfo", data);
  }
};

const actions = {
  setUserInfo: ({ commit }, data) => {
    return new Promise(resolve => {
      commit(types.SET_USER_INFO, data);
      resolve();
    });
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
